package com.tsd.jxc.goods.service.impl;

import java.util.List;
import java.util.Map;
import java.util.Date;
import javax.annotation.Resource;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.jxc.goods.service.JxcGoodsAttrService;
import com.tsd.jxc.goods.entity.JxcGoodsAttr;
import com.tsd.jxc.goods.entity.JxcGoodsAttrExt;
import com.tsd.system.entity.SysUser;
import com.tsd.jxc.goods.dao.JxcGoodsAttrMapper;
import org.springframework.stereotype.Service;
import com.tsd.service.BaseServiceImpl;

/**
 * 描述：JxcGoodsAttr 服务实现层
 *
 * @author david
 * @date 2024/05/07 17:00:24
 */
@Service
public class JxcGoodsAttrServiceImpl extends BaseServiceImpl implements JxcGoodsAttrService {

    @Resource
    private JxcGoodsAttrMapper jxcGoodsAttrMapper;

    @Override
    public JxcGoodsAttr getJxcGoodsAttrById(Long id)throws Exception {
        return jxcGoodsAttrMapper.selectByPrimaryKey(id);
    }

    @Override
    public JxcGoodsAttrExt queryBySid(String sid) throws Exception {
    return jxcGoodsAttrMapper.selectBySid(sid);
    }

    @Override
    public void deleteJxcGoodsAttrs(List<String> list, SysUser opUser)throws Exception {
        for (String sid:list){
            JxcGoodsAttr old = jxcGoodsAttrMapper.selectBySid(sid);
            super.checkEmpty(old,"该记录不存在");
            super.autoInjectBaseData(old,opUser,TYPE_DELETE);
            jxcGoodsAttrMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveJxcGoodsAttr(JxcGoodsAttr record, SysUser opUser) throws Exception {
    	if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record,opUser,TYPE_CREATE);
    		jxcGoodsAttrMapper.insertSelective(record);
    	} else {
            super.autoInjectBaseData(record,opUser,TYPE_UPDATE);
    		jxcGoodsAttrMapper.updateByPrimaryKeySelective(record);
    	}
    }

    @Override
    public List<JxcGoodsAttrExt> findJxcGoodsAttrs(Map<String, Object> params, PageBean page) throws Exception {
    	return jxcGoodsAttrMapper.selectByPage(params, page);
    }

    @Override
    public List<JxcGoodsAttrExt> findJxcGoodsAttrs(Map<String, Object> params) throws Exception {
        return jxcGoodsAttrMapper.selectByParams(params);
    }
}
